﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Web.Mvc;
//using EPiServer.Core;
//using EPiServer.DataAbstraction;
//using EPiServer.Framework.Web;
//using EPiServer.Web;
//using EPiServer.Web.Mvc;
//
//namespace EPiBoost.Core.Web.Mvc.Html
//{
//	public static class IContentDataExtensions
//	{
//		public const string InsideContentAreaMarker = "EPi:InsideContentArea";
//
//		public static void RenderContentData(this HtmlHelper html, IContentData contentData, bool isContentInContentArea)
//		{
//			TemplateModel templateModel = html.ViewContext.HttpContext.GetService<ITemplateResolver>(null).Resolve(html.ViewContext.HttpContext, contentData, TemplateTypeCategories.MvcPartial, (string)(html.ViewContext.ViewData["tag"] as string));
//			html.RenderContentData(contentData, isContentInContentArea, templateModel, html.ViewContext.HttpContext.GetService<IContentRenderer>(null));
//		}
//
//		public static void RenderContentData(this HtmlHelper html, IContentData contentData, bool isContentInContentArea, TemplateModel templateModel, IContentRenderer contentRenderer)
//		{
//			if (contentData != null)
//			{
//				bool? nullable = html.ViewContext.RouteData.DataTokens.ContainsKey(InsideContentAreaMarker) ? new bool?((bool)((bool)html.ViewContext.RouteData.DataTokens[InsideContentAreaMarker])) : null;
//				html.ViewContext.RouteData.DataTokens[InsideContentAreaMarker] = (bool)isContentInContentArea;
//				try
//				{
//					PartialRequest<IContentData> partialRequest = new PartialRequest<IContentData>("Index", contentData);
//					contentRenderer.Render(html.ViewContext, partialRequest, contentData, templateModel);
//				}
//				finally
//				{
//					if (nullable.HasValue)
//					{
//						html.ViewContext.RouteData.DataTokens[InsideContentAreaMarker] = (bool)nullable.Value;
//					}
//					else
//					{
//						html.ViewContext.RouteData.DataTokens.Remove(InsideContentAreaMarker);
//					}
//				}
//			}
//		}
//	}
//}